<template>
  <div v-if="showError">
    <div class="weui-msg">
      <div class="weui-msg__icon-area">
        <i class="weui-icon-warn weui-icon_msg"></i></div>
      <div class="weui-msg__text-area">
        <h2 class="weui-msg__title">信息不存在</h2>
        <p class="weui-msg__desc">您访问的信息已经不存在，有可能已被管理员删除，请与管理员联系。</p>
      </div>
      <div class="weui-msg__opr-area">
        <p class="weui-btn-area">
          <a href="javascript:void (0)" @click="closeWin" class="weui-btn weui-btn_default">确认</a>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
  import wx from "weixin-js-sdk";

  export default {
    name: "MsgTem",
    components: {},
    data() {
      return {
        showError: false,
        form: {
          openId: '',
          kId: '',
          msgId: '',
          msgType: '',
          day: '',
        }
      }
    },
    methods: {
      closeWin() {
        wx.closeWindow();
      },
      getMsg() {
        let msgType = this.form.msgType;
        let msgId = this.form.msgId;
        if ('uh02_report' === msgType) {
          this.$router.push({
            path: '/reportDaily',
            query: {
              id: msgId
            }
          })
        }
        let currentTime = this.form.day;
        this.$http.getMsgDetail({
          msgId: msgId,
          msgType: msgType,
          currentTime: currentTime
        }).then(resp => {
          let data = resp.data;
          if (!data) {
            this.showError = true;
            return;
          }
          let path = '';
          if ('notice' === msgType) {
            path = '/announcementContent';
          } else if ('teaLeave' === msgType) {
            if (this.form.loginType === 'kindergarten') {
              path = '/teaApplyDetails';
            } else {
              path = '/applyDetailsPer';
            }
          } else if ('stuLeave' === msgType) {
            path = '/leaveDetails'
          } else if ('stuPick' === msgType) {
            path = '/stuPick'
          } else if ('teaAtd' === msgType) {
            path = '/teaAtd';
          } else if ('deviceWarn' === msgType) {
            path = '/eqCont';
          } else if ('faceJudge' === msgType) {
            path = '/face-judge';
          }
          this.$router.push({
            path: path,
            query: data
          })
        })
      },
      loginByOpenId() {
        let openId = this.form.openId;
        if (!openId) {
          wx.closeWindow();
          return;
        }
        this.$http.loginByOpenId({
          openId: this.form.openId,
          loginType: this.form.loginType,
          kId: this.form.kId
        }).then(resp => {
          let data = resp.data;
          this.$Cookies.set("token", data.token);
          this.$Cookies.set("fullName", data.fullName);
          this.$Cookies.set("loginType", data.loginType);
          this.$Cookies.set("headImage", data.headImage);
          this.$Cookies.set("custom", data.custom);
          this.$Cookies.set("openId", data.openId);
          this.getMsg();
        })
      }
    },
    created() {
      this.form.openId = this.$route.query.openId;
      this.form.msgId = this.$route.query.msgId;
      this.form.msgType = this.$route.query.msgType;
      this.form.loginType = this.$route.query.loginType;
      this.form.day = this.$route.query.day;
      this.form.kId = this.$route.query.kId;
    },
    mounted() {
      this.loginByOpenId();
    }
  }
</script>

<style scoped>

</style>
